﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetMyTaskDetailEx : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            MyTaskDetailExOutParam result = new MyTaskDetailExOutParam();
            MyTaskDetailExInParam param = new MyTaskDetailExInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as MyTaskDetailExInParam;
                if (string.IsNullOrEmpty(param.user_id) || string.IsNullOrEmpty(param.todo_id) || string.IsNullOrEmpty(param.todo_rel_id))
                {
                    result.code = "0";
                    result.desc = "用户ID,关系ＩＤ,以及待办ID不能为空";

                    isFlag = false;
                }


                if (CommonUtils.IsDisableUsers(param.user_id))
                {
                    result.code = "0";
                    result.desc = "用户状态有问题，请联系管理员";

                    isFlag = false;
                }
                if(isFlag)
                {
                    //获取待办信息
                    DataSet dsTask = InterfaceHelper.GetPartyTaskByID(param.todo_id);

                    if (dsTask == null || dsTask.Tables[0].Rows.Count == 0)
                    {
                        result.code = "0";
                        result.desc = "待办不存在";

                        isFlag = false;
                    }
                    else if(dsTask.Tables[0].Rows[0]["RelationID"].ToString() != param.todo_rel_id.Trim())
                    {
                        result.code = "0";
                        result.desc = "该关系ID不属于该待办";

                        isFlag = false;
                    }
                    else
                    {
                        result.data.type = dsTask.Tables[0].Rows[0]["category"].ToString();
                        result.data.send_time = dsTask.Tables[0].Rows[0]["CreateTime"].ToString();
                        result.data.title = dsTask.Tables[0].Rows[0]["Title"].ToString();  
                    }
                }

                if (isFlag)
                {
                    //获取待办关联表详细信息
                    DataSet dsDetail = InterfaceHelper.GetPartyTaskDetailEx(param.todo_rel_id.Trim());
                    if (dsDetail != null && dsDetail.Tables[0].Rows.Count > 0)
                    {
                        result.data.help_content = dsDetail.Tables[0].Rows[0]["help_content"].ToString();
                        result.data.help_count = dsDetail.Tables[0].Rows[0]["help_count"].ToString();
                        result.data.help_expiry_date = dsDetail.Tables[0].Rows[0]["help_expiry_date"].ToString();
                        result.data.help_name = dsDetail.Tables[0].Rows[0]["help_name"].ToString();
                        result.data.help_person = dsDetail.Tables[0].Rows[0]["help_person"].ToString();
                        result.data.help_type = dsDetail.Tables[0].Rows[0]["help_type"].ToString();
                        result.data.offer_content = dsDetail.Tables[0].Rows[0]["offer_content"].ToString();
                        result.data.offer_count = dsDetail.Tables[0].Rows[0]["offer_count"].ToString();
                        result.data.offer_expiry_date = dsDetail.Tables[0].Rows[0]["offer_expiry_date"].ToString();
                        result.data.offer_name = dsDetail.Tables[0].Rows[0]["offer_name"].ToString();
                        result.data.offer_person = dsDetail.Tables[0].Rows[0]["offer_person"].ToString();
                        result.data.offer_type = dsDetail.Tables[0].Rows[0]["offer_type"].ToString();  
                    } 
                    else
                    {
                        result.code = "0";
                        result.desc = "该关系ID对应的记录不存在";

                        isFlag = false;
                    }
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetMyTaskDetailEx", SerializeHelper.JsonSerializer<MyTaskDetailExInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<MyTaskDetailExInParam, MyTaskDetailExOutParam>();
            else
                SafeProcessRequest<MyTaskDetailExInParam, MyTaskDetailExOutParam>();
        }
    }

    #region 请求参数
    public class MyTaskDetailExInParam
    {
        /// <summary>
        /// 必填 用户ID
        /// </summary>
        public string user_id
        { get; set; }

        /// <summary>
        /// 必填 待办ID
        /// </summary>
        public string todo_id
        { get; set; } 

        /// <summary>
        /// 必填 关系ＩＤ 
        /// </summary>
        public string todo_rel_id
        { get; set; }  
    }
    #endregion

    #region 结果参数
    public class MyTaskDetailExOutParam
    {
        public MyTaskDetailExOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new MyTaskDetailEx();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 待办详情信息
        /// </summary>
        public MyTaskDetailEx data
        { get; set; }
    } 

    /// <summary>
    /// 待办详情信息
    /// </summary>
    public class MyTaskDetailEx
    {
        /// <summary>
        ///	待办标题
        /// </summary>
        public string title
        { get; set; }
        /// <summary>
        ///	待办类型
        /// </summary>
        public string type
        { get; set; }
        /// <summary>
        ///	发送时间
        /// </summary>
        public string send_time
        { get; set; }
        /// <summary>
        ///	求助人名称
        /// </summary>
        public string help_person
        { get; set; }
        /// <summary>
        ///	求助类型
        /// </summary>
        public string help_type
        { get; set; }
        /// <summary>
        ///	求助名称
        /// </summary>
        public string help_name
        { get; set; }
        /// <summary>
        ///	求助数量
        /// </summary>
        public string help_count
        { get; set; }
        /// <summary>
        ///	求助有效期
        /// </summary>
        public string help_expiry_date
        { get; set; }
        /// <summary>
        ///	求助描述
        /// </summary>
        public string help_content
        { get; set; }
        /// <summary>
        ///	捐助人名称
        /// </summary>
        public string offer_person
        { get; set; }
        /// <summary>
        ///	捐助类型
        /// </summary>
        public string offer_type
        { get; set; }
        /// <summary>
        ///	捐助名称
        /// </summary>
        public string offer_name
        { get; set; }
        /// <summary>
        ///	捐助数量
        /// </summary>
        public string offer_count
        { get; set; }
        /// <summary>
        ///	捐助有效期
        /// </summary>
        public string offer_expiry_date
        { get; set; }
        /// <summary>
        ///	捐助描述
        /// </summary>
        public string offer_content
        { get; set; } 
    }
    #endregion 
}